import * as sdk from './fetch';

const controllerName = 'escortTradeController';

/**
 *
 * 查询配送订单
 *
 */
async function findEscorttradeList(params): Promise<BaseResponseString> {
  let result = await sdk.post('escorttrade/page', {
    ...params,
  });
  return result;
}

/**
 *
 * 查询我发布的配送订单
 *
 */
async function findMyEscorttradeList(params): Promise<BaseResponseString> {
  let result = await sdk.post('escorttrade/my/page', {
    ...params,
  });
  return result;
}

/**
 *
 * 查询发布的配送订单详情
 *
 */
async function findEscorttradeDetail(id): Promise<BaseResponseString> {
  let result = await sdk.get(`escorttrade/${id}`,
    {}
  );
  return result;
}

async function getAddressInfo(id): Promise<BaseResponseString> {
  let result = await sdk.get(`customer/address/${id}`,
    {}
  );
  return result;
}

/**
 *
 * 查询我的接单
 *
 */
async function findEscortsnatchorderList(params): Promise<BaseResponseString> {
  let result = await sdk.post('escortsnatchorder/page', {
    ...params,
  });
  return result;
}

/**
 *
 * 查询我的接单详情
 *
 */
async function findEscortsnatchorderDetail(id): Promise<BaseResponseString> {
  let result = await sdk.get(`escortsnatchorder/${id}`,
    {}
  );
  return result;
}

/**
 *
 * 删除我的接单
 *
 */
async function delEscortsnatchorderDetail(id): Promise<BaseResponseString> {
  let result = await sdk.deleteF(`escortsnatchorder/${id}`,
    {}
  );
  return result;
}

/**
 *
 * 删除我的发单
 *
 */
async function delEscorttradeDetail(id): Promise<BaseResponseString> {
  let result = await sdk.deleteF(`escorttrade/${id}`,
    {}
  );
  return result;
}

/**
 *
 * 接单
 *
 */
async function escortsnatchorderAdd(params): Promise<BaseResponseString> {
  let result = await sdk.post(`escortsnatchorder/add`,
    {
      ...params,
    }
  );
  return result;
}

/**
 *
 * 确认完成核销码校验
 *
 */
async function harvestCode(params): Promise<BaseResponseString> {
  let result = await sdk.post(`escortsnatchorder/harvestCode`,
    {
      ...params,
    }
  );
  return result;
}

/**
 *
 * 修改我的接单,支持上传凭证
 *
 */
async function updateEscortsnatchorder(params): Promise<BaseResponseString> {
  let result = await sdk.put(`escortsnatchorder/serviceCertificate`,
    {
      ...params,
    }
  );
  return result;
}

/**
 *
 * 取消订单
 *
 */
async function cancelEscorttrade(params): Promise<BaseResponseString> {
  let result = await sdk.post(`escorttrade/cancel`,
    {
      ...params,
    }
  );
  return result;
}

/**
 *
 * 发布的服务中订单数
 *
 */
async function getEscorttradeCount(): Promise<BaseResponseString> {
  let result = await sdk.get(`escorttrade/inService/count`,
    {}
  );
  return result.context;
}

/**
 *
 * 我的接单服务中订单数
 *
 */
async function getEscortsnatchorderCount(): Promise<BaseResponseString> {
  let result = await sdk.get(`escortsnatchorder/inService/count`,
    {}
  );
  return result.context;
}

export default {
  getAddressInfo,
  findEscorttradeList,
  findMyEscorttradeList,
  findEscorttradeDetail,
  findEscortsnatchorderList,
  findEscortsnatchorderDetail,
  delEscortsnatchorderDetail,
  delEscorttradeDetail,
  escortsnatchorderAdd,
  harvestCode,
  updateEscortsnatchorder,
  cancelEscorttrade,
  getEscorttradeCount,
  getEscortsnatchorderCount,
};

/**
 * This interface was referenced by `IgnoreType`'s JSON-Schema
 * via the `definition` "BaseResponse«string»".
 */
export interface BaseResponseString {
  /**
   * 结果码
   */
  code: string;
  /**
   * 内容
   */
  context?: string;
  /**
   * 错误内容
   */
  errorData?: {
    [k: string]: any;
  };
  /**
   * 消息内容
   */
  message?: string;
  [k: string]: any;
}
